home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / sphigs / sph_mac.hqx / SRGP port to 5.0 (compressed) / SRGP_SPHIGS Root / MacSPHIGS / sph_optimize.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-13  |  3.5 KB  |  125 lines

  1. #include "HEADERS.h"
  2. #include "sphigslocal.h"
  3.  
  4. #include "sph_optimize.proto.h"
  5. static void MergeDescendentList(int);
  6. static void CalculateDescendentListForOneStructure(int);
  7. static void CalculateDescendentListForView(view_spec *);
  8.  
  9. /**
  10. One simple form of optimization is to record, for each view V, a list of the structures
  11. that are subordinates of view V.  This data must be updated in the following ways:
  12.  
  13.  
  14. WHEN A STRUCTURE S IS POSTED TO VIEW V:
  15.     Add S to the subord-list for view V.
  16.     Traverse the network rooted at S:
  17.         Add each encountered structure to the subord-list for view V.
  18.         
  19. WHEN A STRUCTURE S IS UNPOSTED FROM VIEW V:
  20.     Completely recalculate view V's subord-list.
  21.         
  22. WHEN A STRUCTURE P BECOMES A NEW CHILD OF STRUCTURE S:
  23.     Create a temporary subord-list, initially clear.
  24.     Add P to the temp list.
  25.     Traverse the network rooted at P:
  26.         Add each encountered structure to the temp subord-list.
  27.     For each view V:
  28.         If structure S is a subord of view V:
  29.            "OR" the temp subord-list with view V's current subord-list.
  30.             
  31. WHEN A STRUCTURE S IS EDITED IN SUCH A WAY THAT IT POSSIBLY LOST A CHILD:
  32.     For each view V:
  33.         If structure S is posted to view V:
  34.             Completely recalculate view V's subord-list.
  35.             
  36. Here's the algorithm for completely recalculating view V's subord list:
  37.     Clear the subord-list for view V.
  38.     For each structure P still posted to view V:
  39.         Traverse the network rooted at P:
  40.             Add each encountered structure to the subord-list for view V.
  41.  
  42. **/
  43.             
  44.  
  45. static substruct_bitstring temp_descendent_list = NULL;
  46.  
  47.  
  48. /** MERGE DESCENDENT LIST
  49. Uses an optimization algorithm to avoid unnecessary re-traversal.
  50. Warning: assumes bit #sid already set!
  51. **/
  52. static void MergeDescendentList (int sid)
  53. {
  54.    register int s;
  55.    
  56.    for (s=0; s<=MAX_STRUCTURE_ID; s++)
  57.       /* IF STRUCTURE s IS AN IMMEDIATE CHILD OF sid THEN... */
  58.       if (TestBit(SPH__structureTable[sid].child_list, s))
  59.          /* RECURSE ONLY IF STRUCTURE s IS NOT YET RECORDED */
  60.          if ( ! TestBit(temp_descendent_list, s)) {
  61.         SetBit (temp_descendent_list, s);
  62.             MergeDescendentList (s);
  63.          }
  64. }
  65.  
  66.  
  67. static void CalculateDescendentListForOneStructure (int struct_ID)
  68. {
  69.    
  70.    ClearBitstring (&temp_descendent_list);
  71.    SetBit (temp_descendent_list, struct_ID);
  72.    MergeDescendentList (struct_ID);
  73. }
  74.  
  75.  
  76. static void CalculateDescendentListForView (view_spec *vs)
  77. {
  78.    root_header *rptr;
  79.    
  80.    ClearBitstring (&temp_descendent_list);
  81.    
  82.    for (rptr=vs->highestOverlapNetwork; rptr; 
  83.     rptr=rptr->nextLowerOverlapRoot) {    
  84.       SetBit (temp_descendent_list, rptr->root_structID);
  85.       MergeDescendentList (rptr->root_structID);
  86.    }
  87. }
  88.  
  89.  
  90.  
  91. void VIEWOPT__afterNewPosting (view_spec *v, int struct_ID)
  92. {
  93.    CalculateDescendentListForOneStructure (struct_ID);
  94.    MergeBitstring (v->descendent_list, temp_descendent_list);
  95. }
  96.  
  97.  
  98. void VIEWOPT__afterUnposting (view_spec *v, int struct_ID)
  99. {
  100.    CalculateDescendentListForOneStructure (struct_ID);
  101.    MergeBitstring (v->descendent_list, temp_descendent_list);
  102. }
  103.  
  104.  
  105. void VIEWOPT__newExecuteStructure (int ID_of_new_parent, int ID_of_new_child)
  106. {
  107.    register int v;
  108.    
  109.    CalculateDescendentListForOneStructure (ID_of_new_child);
  110.    for (v=0; v<=MAX_VIEW_INDEX; v++)
  111.       if (TestBit(SPH_viewTable[v].descendent_list, ID_of_new_parent))
  112.      MergeBitstring 
  113.         (SPH_viewTable[v].descendent_list, temp_descendent_list);
  114. }
  115.  
  116.  
  117. void VIEWOPT__afterChildLoss (int ID_of_changed_parent)
  118. {
  119.    register int v;
  120.    
  121.    for (v=0; v<=MAX_VIEW_INDEX; v++)
  122.       if (TestBit(SPH_viewTable[v].descendent_list, ID_of_changed_parent))
  123.      CalculateDescendentListForView (&(SPH_viewTable[v]));
  124. }
  125.